<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>signature</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        a {
            text-decoration: none;
        }

        a:hover {
            text-decoration: none;
        }

        ul,
        li {
            list-style-type: none;
        }

        html,
        body {
            width: 100%;
            height: 100%;
            font-family: Arial;
            background-color: #fcfcfc;
            font-size: 18px;
        }

        *,
        *:after,
        *:before {
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
        }

        #wrap {
            height: 100%;
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-orient: vertical;
            -webkit-flex-flow: column;
            flex-flow: column;
        }

        #main {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
            overflow-x: hidden;
            overflow-y: scroll;
        }

        #header {
            background-color: #fe6263;
        }

        .pcc_header {
            width: 100%;
            /*height: 2.2rem;*/
            display: flex;
        }

        .pcc_header .pcc_return {
            width: 4rem;
            height: 2.2rem;
            background: url("../image/retun-icon.png")no-repeat;
            background-size: 0.6rem;
            background-position: 0.7rem center;
        }

        .pcc_header .pcc_title {
            width: 12rem;
            height: 2.2rem;
            line-height: 2.2rem;
            color: #ffffff;
            text-align: center;
            font-size: 0.96rem;
        }

        #aaimg {
            width: 50px;
            height: 50px;
        }

        .pcc_foot {
            width: 100%;
            height: 3.5rem;
            background-color: #ffffff;
            display: flex;
            justify-content: space-between;
            padding: 30px;
        }

        .pcc_foot>div {
            width: 80px;
            height: 35px;
            text-align: center;
            line-height: 35px;
            font-size: 16px;
            border-radius: 4px;
        }

        .pcc_foot>div:nth-child(1) {
            background-color: #817e7e;
            color: #ffffff;
        }

        .pcc_foot>div:nth-child(2) {
            background-color: #fe6263;
            color: #ffffff;
        }

        .pcc_zhanwei {
            width: 100%;
            height: 400px;
        }
    </style>
</head>

<body>
    <div id="wrap">
        <div id="header">
            <div class="pcc_header">
                <a class="pcc_return" href="#" onclick="closeappend();"></a>
                <p class="pcc_title">签名</p>
                <span style="width:4rem"></span>
            </div>
        </div>
        <div id="main">
            <div class="pcc_zhanwei"></div>
            <div class="pcc_foot">
                <div onclick="clearimg();">清除</div>
                <div onclick="saveimg();">保存</div>
            </div>
        </div>

    </div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    apiready = function() {
        var header = $api.byId('header');
        //适配iOS 7+，Android 4.4+状态栏
        $api.fixStatusBar(header);

        var headerPos = $api.offset(header);

        var drawingBoard = api.require('drawingBoard');
        drawingBoard.open({
            rect: {
                x: 0,
                y: headerPos.h,
                w: 375,
                h: 400
            },
            styles: {
                brush: {
                    color: '#000000',
                    width: 4
                },
                bgColor: '#eeeeee'
            },
            fixedOn: api.frameName
        });

    };
    // 保存图片
    function saveimg() {
        var drawingBoard = api.require('drawingBoard');
        drawingBoard.save({
            savePath: 'fs://drawingBoard/result.png',
            copyToAlbum: false
        }, function(ret) {
            // alert(JSON.stringify(ret));
            var imgsrc = api.fsDir + '/' + 'drawingBoard/result.png';
            api.sendEvent({
                name: 'signature',
                extra: {
                    key: imgsrc
                }
            });

            api.closeWin();
        });
    };
    // 清除内容
    function clearimg() {
        var drawingBoard = api.require('drawingBoard');
        drawingBoard.clear();
    };
    //关闭本窗口
    function closeappend() {
        api.closeWin();
    };
</script>

</html>
